/*
 *  levelUpGame - GridObject.h
 *  Copyright 2011 W. Reckman. All rights reserved.
 */
#ifndef GRID_OBJECT_H
#define GRID_OBJECT_H

#include "GameModel.h"
#include "SerialDevice.h" //FIXME: merge enums?
#include "BoundingBox.h"

class LevelUpApp;
class GameModel;

class GridObject : public BoundingBox {
public:
	enum COLLISION_MODE { CM_BBOX, CM_CENTER, CM_CIRCLE };
	
	explicit GridObject( const LevelUpApp& appRef_, bool movable_ = true );
	virtual ~GridObject();
	
	void draw() const;
	
	COLLISION_MODE getCollisionMode() const;
	bool isMovable() const;
	bool isCollidable() const;
	int getMovementSpeed() const;
	DIRECTION getDirection() const;
	bool isBlocked() const;

	void setCollisionMode( COLLISION_MODE mode_ );
	void setMovable( bool movable_ );
	void setCollidable( bool collidable_ );
	void setMovementSpeed( int speed_ );
	void setDirection( DIRECTION direction_, bool setCurrentDir = false );
	void setDirection( EventArgsJoystick::DIRECTION direction_, bool setCurrentDir = false ); //FIXME: merge enums?
	void setBlocked( bool blocked_ );
	
	bool tryMovingTo( const ofPoint& pos_, DIRECTION dir );
	bool tryMovingTo( float x_, float y_, DIRECTION dir );
	
	bool collidesWith( const GridObject& other_ ) const;
		
protected:
	const LevelUpApp& appRef;
	const GameModel& game;
	int movementSpeed;
	DIRECTION currentDir;
	DIRECTION intendedDir;
	bool blocked;
	
//	virtual void setPosition( float x_, float y_ );
//	virtual void setPosition( const ofPoint& pos_ );
	bool calculateNewPosForDirection( DIRECTION dir, float elapsedTime, ofPoint& newPos ) const;
	float getFakeRadius() const;
	
private:
	COLLISION_MODE collisionMode;
	bool movable;
	bool collidable;
	bool boundToGrid;
};

#endif /* ! GRID_OBJECT_H */
